package com.dominator.controller.api;

import com.dominFramework.core.utils.JsonUtils;
import com.dominator.enums.ReqEnums;
import com.dominator.service.ApiWcService;
import com.dominator.utils.api.ApiMessage;
import com.dominator.utils.exception.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/api/v1/wc2018")
@Slf4j
public class ApiWcController {

    @Autowired
    HttpServletRequest request;

    @Autowired
    ApiWcService apiWcService;



    /**
     * 创建球队
     *
     * @param paramStr
     * @return
     */
    @RequestMapping("/createTeam")
    @ResponseBody
    public ApiMessage createTeam(@RequestParam String paramStr) {
        ApiMessage msg;
        try {
            msg = apiWcService.createTeam(JsonUtils.toDto(paramStr));
        } catch (ApiException e) {
            msg = new ApiMessage(e.getCode(), e.getMessage());
        } catch (Exception e) {
            msg = new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        }
        return msg;

    }





    /**
     * 球队改名
     *
     * @param paramStr
     * @return
     */
    @RequestMapping("/modifyTeam")
    @ResponseBody
    public ApiMessage modifyTeam(@RequestParam String paramStr) {
        ApiMessage msg;
        try {
            msg = apiWcService.modifyTeam(JsonUtils.toDto(paramStr));
        } catch (ApiException e) {
            msg = new ApiMessage(e.getCode(), e.getMessage());
        } catch (Exception e) {
            msg = new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        }
        return msg;

    }


    /**
     *
     * 某日期所有战队排名
     * @param paramStr
     * @return
     */
    @RequestMapping("/getRankList")
    @ResponseBody
    public ApiMessage getRankList(@RequestParam String paramStr) {
        ApiMessage msg;
        try {
            msg = apiWcService.getRankList(JsonUtils.toDto(paramStr));
        } catch (ApiException e) {
            msg = new ApiMessage(e.getCode(), e.getMessage());
        } catch (Exception e) {
            msg = new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        }
        return msg;

    }

    /**
     *
     * 手机号所属战队某日期的排名
     * @param paramStr
     * @return
     */
    @RequestMapping("/getMyRankList")
    @ResponseBody
    public ApiMessage getMyRankList(@RequestParam String paramStr) {
        ApiMessage msg;
        try {
            msg = apiWcService.getMyRankList(JsonUtils.toDto(paramStr));
        } catch (ApiException e) {
            msg = new ApiMessage(e.getCode(), e.getMessage());
        } catch (Exception e) {
            msg = new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        }
        return msg;

    }



    /**
     *
     * 战队贡献
     * @param paramStr
     * @return
     */
    @RequestMapping("/getTeamRateList")
    @ResponseBody
    public ApiMessage getTeamRateList(@RequestParam String paramStr) {
        ApiMessage msg;
        try {
            msg = apiWcService.getTeamRateList(JsonUtils.toDto(paramStr));
        } catch (ApiException e) {
            msg = new ApiMessage(e.getCode(), e.getMessage());
        } catch (Exception e) {
            msg = new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        }
        return msg;

    }

    /**
     *
     * 查询我的战队名称
     * @param paramStr
     * @return
     */
    @RequestMapping("/getMyTeam")
    @ResponseBody
    public ApiMessage getMyTeam(@RequestParam String paramStr) {
        ApiMessage msg;
        try {
            msg = apiWcService.getMyTeam(JsonUtils.toDto(paramStr));
        } catch (ApiException e) {
            msg = new ApiMessage(e.getCode(), e.getMessage());
        } catch (Exception e) {
            msg = new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        }
        return msg;

    }

    /**
     *
     * 查询我的战队成员贡献
     * @param paramStr
     * @return
     */
    @RequestMapping("/getMyTeamMemberRate")
    @ResponseBody
    public ApiMessage getMyTeamMemberRate(@RequestParam String paramStr) {
        ApiMessage msg;
        try {
            msg = apiWcService.getMyTeamMemberRate(JsonUtils.toDto(paramStr));
        } catch (ApiException e) {
            msg = new ApiMessage(e.getCode(), e.getMessage());
        } catch (Exception e) {
            msg = new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        }
        return msg;

    }

    /**
     * 加入球队
     *
     * @param paramStr
     * @return
     */
    @RequestMapping("/joinTeam")
    @ResponseBody
    public ApiMessage joinTeam(@RequestParam String paramStr) {
        ApiMessage msg;
        try {
            msg = apiWcService.joinTeam(JsonUtils.toDto(paramStr));
        } catch (ApiException e) {
            msg = new ApiMessage(e.getCode(), e.getMessage());
        } catch (Exception e) {
            msg = new ApiMessage(ReqEnums.SYS_ERROR);
            e.printStackTrace();
        }
        return msg;

    }
}
